package com.blog.system.constant;

import java.io.Serializable;

/**
 * @PackgeName: com.blog.system.constant
 * @ClassName: JsonResult
 * @Author: wangyu
 * Date: 2021/3/16 9:08
 * project name: system
 * @Version:
 * @Description: 统一json返回类
 */
public class JsonResult<T> implements Serializable {

	private Boolean success;
	private Integer errorCode;
	private String errorMsg;
	private T data;

	public JsonResult() {
	}

	public JsonResult(boolean success) {
		this.success = success;
		this.errorCode = success ? ResultCode.SUCCESS.getCode() : ResultCode.COMMON_FAIL.getCode();
		this.errorMsg = success ? ResultCode.SUCCESS.getMessage() : ResultCode.COMMON_FAIL.getMessage();
	}

	public JsonResult(boolean success, ResultCode resultEnum) {
		this.success = success;
		this.errorCode = success ? ResultCode.SUCCESS.getCode() : (resultEnum == null ? ResultCode.COMMON_FAIL.getCode() : resultEnum.getCode());
		this.errorMsg = success ? ResultCode.SUCCESS.getMessage() : (resultEnum == null ? ResultCode.COMMON_FAIL.getMessage() : resultEnum.getMessage());
	}

	public JsonResult(boolean success, T data) {
		this.success = success;
		this.errorCode = success ? ResultCode.SUCCESS.getCode() : ResultCode.COMMON_FAIL.getCode();
		this.errorMsg = success ? ResultCode.SUCCESS.getMessage() : ResultCode.COMMON_FAIL.getMessage();
		this.data = data;
	}

	public JsonResult(boolean success, ResultCode resultEnum, T data) {
		this.success = success;
		this.errorCode = success ? ResultCode.SUCCESS.getCode() : (resultEnum == null ? ResultCode.COMMON_FAIL.getCode() : resultEnum.getCode());
		this.errorMsg = success ? ResultCode.SUCCESS.getMessage() : (resultEnum == null ? ResultCode.COMMON_FAIL.getMessage() : resultEnum.getMessage());
		this.data = data;
	}

	public Boolean getSuccess() {
		return success;
	}

	public void setSuccess(Boolean success) {
		this.success = success;
	}

	public Integer getErrorCode() {
		return errorCode;
	}

	public void setErrorCode(Integer errorCode) {
		this.errorCode = errorCode;
	}

	public String getErrorMsg() {
		return errorMsg;
	}

	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}
}
